package com.xydtech.ecard.merchant.controller;

import com.alibaba.fastjson.JSONObject;
import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.domain.entity.SysDept;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.DateUtils;
import com.xydtech.common.utils.ShiroUtils;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.merchant.domain.*;
import com.xydtech.ecard.merchant.domain.echarts.EcardBaseLineChartEntity;
import com.xydtech.ecard.merchant.service.IEcardBranchEcardChartService;
import com.xydtech.system.domain.SysPost;
import com.xydtech.system.service.ISysConfigService;
import com.xydtech.system.service.ISysDeptService;
import com.xydtech.system.service.ISysPostService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * 电子名片图表统计
 *
 * @author yuzhiguo
 * @date 2024-05-22 上午10:25
 */
@Controller
@RequestMapping("/merchant/ecardChart")
public class EcardBranchEcardChartController extends BaseController {

    @Autowired
    private IEcardBranchEcardChartService ecardBranchEcardChartService;

    @Autowired
    private ISysPostService sysPostService;

    @Autowired
    private ISysConfigService sysConfigService;

    @Autowired
    private ISysDeptService sysDeptService;

    private String prefix = "merchant";

    @GetMapping
    @RequiresPermissions("merchant:branchEcardChart:view")
    public String mainData(ModelMap mmap) {
        Long userId = ShiroUtils.getUserId();
        Long deptId = ShiroUtils.getSysUser().getDeptId();
        List<SysPost> sysPosts = sysPostService.selectPostByUserId(userId);
        if (sysPosts.size() > 0){
            Long postId = sysPosts.get(0).getPostId();//主岗位id
            if (postId == 2) {
                mmap.put("type", "1");//客户经理
            }
            if (postId == 10) {
                mmap.put("type", "2");//网格管理
            }
        } else {
            mmap.put("type", "1");//客户经理
        }
        mmap.put("filingVisits", ecardBranchEcardChartService.getFilingVisitsStatistics(userId));//个人建档拜访数量
        mmap.put("allFilingVisits", ecardBranchEcardChartService.getAllFilingVisitsNums(deptId));//全行建档拜访数量
        mmap.put("timeoutVisits", ecardBranchEcardChartService.getTimeoutVisitsNums(deptId));//超时拜访数量
        mmap.put("generationTime", DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", new Date()));
        return prefix + "/branchEcardChart";
    }

    /**
     * 查询建档折线图数据
     *
     * @return
     */
    @RequestMapping("/getFilingLineChart")
    @ResponseBody
    public Object getFilingLineChart() {
        Long deptId = ShiroUtils.getSysUser().getDeptId();
        //组装图表
        EcardBaseLineChartEntity stackedLineChartEntity = new EcardBaseLineChartEntity();

        //查询建档折线图数据
        List<EcardBranchEcardChart> filingLineChartData = ecardBranchEcardChartService.getFilingLineChart(deptId);
        EcardBaseLineChartEntity.XAxis xAxis = stackedLineChartEntity.getXAxis();

        EcardBaseLineChartEntity.Series filingSeries = new EcardBaseLineChartEntity.Series();
        filingSeries.setName("建档数量趋势");
        for (EcardBranchEcardChart lineChartDatum : filingLineChartData) {
            filingSeries.getData().add(lineChartDatum.getMerchantNum());
            xAxis.getData().add(lineChartDatum.getMonth());
        }
        stackedLineChartEntity.getSeries().add(filingSeries);
        return JSONObject.toJSON(stackedLineChartEntity);
    }

    /**
     * 查询拜访折线图数据
     *
     * @return
     */
    @RequestMapping("/getVisitLineChart")
    @ResponseBody
    public Object getVisitLineChart() {
        Long deptId = ShiroUtils.getSysUser().getDeptId();
        //组装图表
        EcardBaseLineChartEntity stackedLineChartEntity = new EcardBaseLineChartEntity();

        //查询建档折线图数据
        List<EcardBranchEcardChart> visitLineChartData = ecardBranchEcardChartService.getVisitLineChart(deptId);
        EcardBaseLineChartEntity.XAxis xAxis = stackedLineChartEntity.getXAxis();

        EcardBaseLineChartEntity.Series visitSeries = new EcardBaseLineChartEntity.Series();
        visitSeries.setName("拜访数量趋势");
        for (EcardBranchEcardChart lineChartDatum : visitLineChartData) {
            visitSeries.getData().add(lineChartDatum.getVisitSum());
            xAxis.getData().add(lineChartDatum.getMonth());
        }
        stackedLineChartEntity.getSeries().add(visitSeries);
        return JSONObject.toJSON(stackedLineChartEntity);
    }

    /**
     * 跳转机构建档拜访统计
     *
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:view")
    @GetMapping("/branchFilingVisitsDept")
    public String branchFilingVisitsDept() {
        return prefix + "/branchFilingVisitsDept";
    }

    /**
     * 机构商户建档排名
     *
     * @param ecardBranchDeptFiling
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:list")
    @PostMapping("/getDeptFilingList")
    @ResponseBody
    public TableDataInfo getDeptFilingList(EcardBranchDeptFiling ecardBranchDeptFiling) {
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchDeptFiling.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchDeptFiling.setDeptId(sysDept.getDeptId());
        startPage();
        List<EcardBranchDeptFiling> list = ecardBranchEcardChartService.getDeptFilingListByApplet(ecardBranchDeptFiling);
        return getDataTable(list);
    }

    /**
     * 导出机构商户建档排名信息
     *
     * @param ecardBranchDeptFiling
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:export")
    @Log(title = "导出机构商户建档排名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exportDeptFilingList")
    @ResponseBody
    public AjaxResult exportDeptFilingList(EcardBranchDeptFiling ecardBranchDeptFiling) {
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchDeptFiling.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchDeptFiling.setDeptId(sysDept.getDeptId());
        List<EcardBranchDeptFiling> list = ecardBranchEcardChartService.getDeptFilingListByApplet(ecardBranchDeptFiling);
        ExcelUtil<EcardBranchDeptFiling> util = new ExcelUtil<EcardBranchDeptFiling>(EcardBranchDeptFiling.class);
        return util.exportExcel(list, "机构商户建档排名信息");
    }

    /**
     * 机构拜访次数排名
     *
     * @param ecardBranchDeptVisit
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:list")
    @PostMapping("/getDeptVisitsList")
    @ResponseBody
    public TableDataInfo getDeptVisitsList(EcardBranchDeptVisit ecardBranchDeptVisit) {
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchDeptVisit.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchDeptVisit.setDeptId(sysDept.getDeptId());
        startPage();
        List<EcardBranchDeptVisit> list = ecardBranchEcardChartService.getDeptVisitsListByApplet(ecardBranchDeptVisit);
        return getDataTable(list);
    }

    /**
     * 导出机构拜访次数排名信息
     *
     * @param ecardBranchDeptVisit
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:export")
    @Log(title = "导出机构拜访次数排名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exportDeptVisitsList")
    @ResponseBody
    public AjaxResult exportDeptVisitsList(EcardBranchDeptVisit ecardBranchDeptVisit) {
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchDeptVisit.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchDeptVisit.setDeptId(sysDept.getDeptId());
        List<EcardBranchDeptVisit> list = ecardBranchEcardChartService.getDeptVisitsListByApplet(ecardBranchDeptVisit);
        ExcelUtil<EcardBranchDeptVisit> util = new ExcelUtil<EcardBranchDeptVisit>(EcardBranchDeptVisit.class);
        return util.exportExcel(list, "机构拜访次数排名信息");
    }

    /**
     * 机构超时拜访次数排名
     *
     * @param ecardBranchDeptDoTask
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:list")
    @PostMapping("/getDeptDoTaskList")
    @ResponseBody
    public TableDataInfo getDeptDoTaskList(EcardBranchDeptDoTask ecardBranchDeptDoTask) {
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchDeptDoTask.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchDeptDoTask.setDeptId(sysDept.getDeptId());
        startPage();
        List<EcardBranchDeptDoTask> list = ecardBranchEcardChartService.getDeptDoTaskListByApplet(ecardBranchDeptDoTask);
        return getDataTable(list);
    }

    /**
     * 导出机构超时拜访次数排名信息
     *
     * @param ecardBranchDeptDoTask
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:export")
    @Log(title = "导出机构超时拜访次数排名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exportDeptDoTaskList")
    @ResponseBody
    public AjaxResult exportDeptDoTaskList(EcardBranchDeptDoTask ecardBranchDeptDoTask) {
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchDeptDoTask.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchDeptDoTask.setDeptId(sysDept.getDeptId());
        List<EcardBranchDeptDoTask> list = ecardBranchEcardChartService.getDeptDoTaskListByApplet(ecardBranchDeptDoTask);
        ExcelUtil<EcardBranchDeptDoTask> util = new ExcelUtil<EcardBranchDeptDoTask>(EcardBranchDeptDoTask.class);
        return util.exportExcel(list, "机构超时拜访次数排名信息");
    }

    /**
     * 机构超时未拜访次数排名
     *
     * @param ecardBranchDeptUndoTask
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:list")
    @PostMapping("/getDeptUnDoTaskList")
    @ResponseBody
    public TableDataInfo getDeptUnDoTaskList(EcardBranchDeptUndoTask ecardBranchDeptUndoTask) {
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchDeptUndoTask.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchDeptUndoTask.setDeptId(sysDept.getDeptId());
        startPage();
        List<EcardBranchDeptUndoTask> list = ecardBranchEcardChartService.getDeptUnDoTaskListByApplet(ecardBranchDeptUndoTask);
        return getDataTable(list);
    }

    /**
     * 导出机构超时未拜访次数排名信息
     *
     * @param ecardBranchDeptUndoTask
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:export")
    @Log(title = "导出机构超时拜访次数排名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exportDeptUnDoTaskList")
    @ResponseBody
    public AjaxResult exportDeptUnDoTaskList(EcardBranchDeptUndoTask ecardBranchDeptUndoTask) {
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchDeptUndoTask.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchDeptUndoTask.setDeptId(sysDept.getDeptId());
        List<EcardBranchDeptUndoTask> list = ecardBranchEcardChartService.getDeptUnDoTaskListByApplet(ecardBranchDeptUndoTask);
        ExcelUtil<EcardBranchDeptUndoTask> util = new ExcelUtil<EcardBranchDeptUndoTask>(EcardBranchDeptUndoTask.class);
        return util.exportExcel(list, "机构超时拜访次数排名信息");
    }

    /**
     * 跳转营销人员建档拜访统计
     *
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:view")
    @GetMapping("/branchFilingVisitsUser")
    public String branchFilingVisitsUser() {
        return prefix + "/branchFilingVisitsUser";
    }

    /**
     * 营销人员商户建档排名
     *
     * @param ecardBranchUserFiling
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:list")
    @PostMapping("/getUserFilingList")
    @ResponseBody
    public TableDataInfo getUserFilingList(EcardBranchUserFiling ecardBranchUserFiling) {
        ecardBranchUserFiling.setAppQueryDeptId(ecardBranchUserFiling.getDeptId());
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchUserFiling.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchUserFiling.setDeptId(sysDept.getDeptId());
        startPage();
        List<EcardBranchUserFiling> list = ecardBranchEcardChartService.getUserFilingListByApplet(ecardBranchUserFiling);
        return getDataTable(list);
    }

    /**
     * 导出营销人员建档排名信息
     *
     * @param ecardBranchUserFiling
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:export")
    @Log(title = "导出营销人员建档排名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exportUserFilingList")
    @ResponseBody
    public AjaxResult exportUserFilingList(EcardBranchUserFiling ecardBranchUserFiling) {
        ecardBranchUserFiling.setAppQueryDeptId(ecardBranchUserFiling.getDeptId());
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchUserFiling.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchUserFiling.setDeptId(sysDept.getDeptId());
        List<EcardBranchUserFiling> list = ecardBranchEcardChartService.getUserFilingListByApplet(ecardBranchUserFiling);
        ExcelUtil<EcardBranchUserFiling> util = new ExcelUtil<EcardBranchUserFiling>(EcardBranchUserFiling.class);
        return util.exportExcel(list, "营销人员建档排名信息");
    }

    /**
     * 营销人员拜访次数排名
     *
     * @param ecardBranchUserVisit
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:list")
    @PostMapping("/getUserVisitsList")
    @ResponseBody
    public TableDataInfo getUserVisitsList(EcardBranchUserVisit ecardBranchUserVisit) {
        ecardBranchUserVisit.setAppQueryDeptId(ecardBranchUserVisit.getDeptId());
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchUserVisit.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchUserVisit.setDeptId(sysDept.getDeptId());
        startPage();
        List<EcardBranchUserVisit> list = ecardBranchEcardChartService.getUserVisitsListByApplet(ecardBranchUserVisit);
        return getDataTable(list);
    }

    /**
     * 导出营销人员拜访次数排名信息
     *
     * @param ecardBranchUserVisit
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:export")
    @Log(title = "导出营销人员拜访次数排名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exportUserVisitsList")
    @ResponseBody
    public AjaxResult exportUserVisitsList(EcardBranchUserVisit ecardBranchUserVisit) {
        ecardBranchUserVisit.setAppQueryDeptId(ecardBranchUserVisit.getDeptId());
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchUserVisit.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchUserVisit.setDeptId(sysDept.getDeptId());
        List<EcardBranchUserVisit> list = ecardBranchEcardChartService.getUserVisitsListByApplet(ecardBranchUserVisit);
        ExcelUtil<EcardBranchUserVisit> util = new ExcelUtil<EcardBranchUserVisit>(EcardBranchUserVisit.class);
        return util.exportExcel(list, "营销人员拜访次数排名信息");
    }

    /**
     * 营销人员超时拜访次数排名
     *
     * @param ecardBranchUserDoTask
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:list")
    @PostMapping("/getUserDoTaskList")
    @ResponseBody
    public TableDataInfo getUserDoTaskList(EcardBranchUserDoTask ecardBranchUserDoTask) {
        ecardBranchUserDoTask.setAppQueryDeptId(ecardBranchUserDoTask.getDeptId());
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchUserDoTask.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchUserDoTask.setDeptId(sysDept.getDeptId());
        startPage();
        List<EcardBranchUserDoTask> list = ecardBranchEcardChartService.getUserDoTaskListByApplet(ecardBranchUserDoTask);
        return getDataTable(list);
    }

    /**
     * 导出营销人员超时拜访次数排名
     *
     * @param ecardBranchUserDoTask
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:export")
    @Log(title = "导出营销人员超时拜访次数排名", businessType = BusinessType.EXPORT)
    @PostMapping("/exportUserDoTaskList")
    @ResponseBody
    public AjaxResult exportUserDoTaskList(EcardBranchUserDoTask ecardBranchUserDoTask) {
        ecardBranchUserDoTask.setAppQueryDeptId(ecardBranchUserDoTask.getDeptId());
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchUserDoTask.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchUserDoTask.setDeptId(sysDept.getDeptId());
        List<EcardBranchUserDoTask> list = ecardBranchEcardChartService.getUserDoTaskListByApplet(ecardBranchUserDoTask);
        ExcelUtil<EcardBranchUserDoTask> util = new ExcelUtil<EcardBranchUserDoTask>(EcardBranchUserDoTask.class);
        return util.exportExcel(list, "营销人员超时拜访次数排名");
    }

    /**
     * 营销人员超时未拜访次数排名
     *
     * @param ecardBranchUserUndoTask
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:list")
    @PostMapping("/getUserUnDoTaskList")
    @ResponseBody
    public TableDataInfo getUserUnDoTaskList(EcardBranchUserUndoTask ecardBranchUserUndoTask) {
        ecardBranchUserUndoTask.setAppQueryDeptId(ecardBranchUserUndoTask.getDeptId());
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchUserUndoTask.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchUserUndoTask.setDeptId(sysDept.getDeptId());
        startPage();
        List<EcardBranchUserUndoTask> list = ecardBranchEcardChartService.getUserUnDoTaskListByApplet(ecardBranchUserUndoTask);
        return getDataTable(list);
    }

    /**
     * 导出营销人员超时未拜访次数排名
     *
     * @param ecardBranchUserUndoTask
     * @return
     */
    @RequiresPermissions("merchant:branchFilingVisits:export")
    @Log(title = "导出营销人员超时未拜访次数排名", businessType = BusinessType.EXPORT)
    @PostMapping("/exportUserUnDoTaskList")
    @ResponseBody
    public AjaxResult exportUserUnDoTaskList(EcardBranchUserUndoTask ecardBranchUserUndoTask) {
        ecardBranchUserUndoTask.setAppQueryDeptId(ecardBranchUserUndoTask.getDeptId());
        SysDept dept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());
        //是否只查业务条线（支行和分理处，不含总行各部室），0：是，1：否
        String ecardMerchantIsdept = sysConfigService.selectConfigByKey("ecard_merchant_isdept", dept.getDeptId());
        if ("0".equals(ecardMerchantIsdept)){
            ecardBranchUserUndoTask.setIsServiceLine(ecardMerchantIsdept);//是
        }
        SysDept sysDept = sysDeptService.selectSecondLevelDeptByDeptId(ShiroUtils.getSysUser().getDeptId());//获取县级机构
        ecardBranchUserUndoTask.setDeptId(sysDept.getDeptId());
        List<EcardBranchUserUndoTask> list = ecardBranchEcardChartService.getUserUnDoTaskListByApplet(ecardBranchUserUndoTask);
        ExcelUtil<EcardBranchUserUndoTask> util = new ExcelUtil<EcardBranchUserUndoTask>(EcardBranchUserUndoTask.class);
        return util.exportExcel(list, "营销人员超时未拜访次数排名");
    }
}
